<?php

namespace app\common\model;

use think\Model;

/**
 * 消息记录
 */
class MessageLogs Extends Model
{

    // 表名
    protected $name = 'message_logs';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = false;
    // 追加属性
    protected $append = [
    ];
    // 新增消息记录
    public static function addMessage($data=[],$wechat_id){
        $data = [
            'wechat_id' => intval($wechat_id),
            'openid'    => $data['FromUserName'],
            'msg_type'  => $data['MsgType'],
            'url'       => (isset($data['PicUrl']) ? $data['PicUrl'] : ''),
            'content'   => (isset($data['Content']) ? $data['Content'] : ''),
            'media_id'  => (isset($data['MediaId']) ? $data['MediaId'] : ''), 
            'msg_id'    => (isset($data['MsgId']) ? $data['MsgId'] : ''), 
            'format'    => (isset($data['Format']) ? $data['Format'] : ''),
            'recognition' => (isset($data['Recognition']) ? $data['Recognition'] : ''),
            'thumb_media_id' => (isset($data['ThumbMediaId']) ? $data['ThumbMediaId'] : ''),
            'create_time'    => time(),
        ];
        return self::insert($data,true,true);
    }
    public function member()
    {
        return $this->belongsTo('Members','openid' ,'openid');
    }
}
